#!/bin/env python
import sys
import random
import string

def gen_word(l):
  res = ''
  for i in range(l):
    z = random.randint(0, 25)
    res += string.ascii_lowercase[z]
  return res

def main():
  try:
    f = open(sys.argv[1], 'w')
    n = int(sys.argv[2])
  except:
    print >> sys.stderr, 'usage: %s <output-file> <# lines>' % sys.argv[0]
    sys.exit(1)
  line = 0
  column = 0
  percent = 0
  while True:
    word_len = random.randint(2, 10)
    word = gen_word(word_len)
    if word_len + 1 + column > 80:
      print >> f
      line += 1
      column = 0
      while line * 100 >= percent * n:
        print >> sys.stderr, '[info] %d%% completed\r' % percent,
        percent += 1
      if line >= n: break
    print >> f, word,
    column += word_len + 1
  print >> sys.stderr
  print >> sys.stderr, '[info] text file generated'
  print >> sys.stderr, '[info] # lines = %d' % n

if __name__ == '__main__':
  main()
